<%@ page language="java"  pageEncoding="UTF-8" %>
<%@ page import="com.shopping.modean.*" %>
<%@ page import="com.shopping.service.*" %>
<%@ page import="java.util.*" %>

<%	

	User u = (User)session.getAttribute("user");
	if(u == null) {
		response.sendRedirect("login.jsp");
		return;
	}
	Cart cart = (Cart)session.getAttribute("cart");
	if(cart == null) {
		response.sendRedirect("index.jsp");
		return;
	}
	
	String addr = request.getParameter("addr");
	SaleOrder so = new SaleOrder();
	so.setAddr(addr);
	so.setUserId(u.getId());
	so.setStatus(0);//用户新下单
	
	List<SaleItem> saleItems = new ArrayList<SaleItem>();
	for(CartItem item : cart.getItems()) {
		SaleItem si = new SaleItem();
		si.setProductId(item.getProductId());
		si.setPcount(item.getCount());
		si.setUnitPrice(item.getPrice());
		saleItems.add(si);
	}
	so.setSaleItem(saleItems);
	
	OrderService.getInstance().add(so);
	session.removeAttribute("cart");
%>

<!DOCTYPE html>
<html>
<head>
  <title>确认订单</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="text/javascript" src="script/regcheckdata.js"></script>
</head>

<body>
	
	<center>
		谢谢您在本站购物，欢迎下次光临！
	</center>
	
</body>
</html>